package fdoj.eventInvitations.servlet;

import java.io.IOException;
import java.util.Properties;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fdoj.eventInvitations.dao.PersonDao;
import fdoj.eventInvitations.entity.Person;

public class FbContactsController extends HttpServlet {

	@EJB
	PersonDao personDao;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession(true);
			Person loggedUser = (Person) session.getAttribute("loggedUser");
			if (loggedUser != null) {
				String apiKey = "146344502099847";
				String redirectURL = "http://localhost:8080/PozivNaDogadjaj/fbcontactsapi";
				String scopes="read_friendlists,offline_access,email";
				String url=FacebookAPI.getURL(apiKey, redirectURL, scopes);
				response.sendRedirect(response.encodeRedirectURL(url));
				return;
			}else{
				response.sendRedirect(response.encodeRedirectURL("./index"));
				return;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.sendRedirect("./index");

	}
}
